<?php

function getNonceStr($length){
	$str = NULL;
	$strPol = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
	$max = strlen($strPol) - 1;
	for($i = 0;$i < $length;$i++){
		$str .= $strPol[rand(0,$max)];
	}
	return $str;
}

function getSign($Obj,$key){

     foreach ($Obj as $k => $v){
        $Parameters[$k] = $v;
     }

     ksort($Parameters);
     $String = formatBizQueryParaMap($Parameters, false);

     $String = $String."&key=".$key;

     $String = md5($String);

     $result = strtoupper($String);

     return $result;
}

function formatBizQueryParaMap($paraMap, $urlencode){

    $buff = "";
    ksort($paraMap);
    foreach ($paraMap as $k => $v)
    {
        if($urlencode){
            $v = urlencode($v);
        }
        $buff .= $k . "=" . $v . "&";
    }
    $reqPar = '';
    if (strlen($buff) > 0){
        $reqPar = substr($buff, 0, strlen($buff)-1);
    }
    return $reqPar;
}

function arrayToXml($arr){ 
    $xml = "<xml>"; 
    foreach ($arr as $key=>$val){ 
        if(is_numeric($val)){ 
            $xml.="<".$key.">".$val."</".$key.">"; 
        }else{ 
            $xml.="<".$key."><![CDATA[".$val."]]></".$key.">"; 
        } 
    } 
    $xml.="</xml>"; 
    return $xml; 
}

function xmlToUrl($xml,$url){
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

?>